package com.ym521.emojipack.keyboard.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.ym521.emojipack.R;
import com.ym521.emojipack.emoji.EmojiPack;
import com.ym521.emojipack.keyboard.EmoiiPackClickListener;
import com.ym521.emojipack.keyboard.adapter.viewHolder.EmojiPackItemViewHolder;

import java.util.ArrayList;
import java.util.List;


/**
 * @author Ym
 */
public final class EmojiPackItemAdapter extends RecyclerView.Adapter<EmojiPackItemViewHolder> {
    private boolean mUseSystemDefault;
    private List<EmojiPack> dataList = new ArrayList<>();
    public EmoiiPackClickListener listener;

    public void addAllData(List<EmojiPack> dataList, boolean useSystemDefault) {
        this.mUseSystemDefault = useSystemDefault;
        int index = this.dataList.size();
        this.dataList.addAll(dataList);
        notifyItemRangeInserted(index, dataList.size());
    }

    public void addAllData(List<EmojiPack> dataList) {
        this.mUseSystemDefault = false;
        int index = this.dataList.size();
        this.dataList.addAll(dataList);
        notifyItemRangeInserted(index, dataList.size());
    }

    @NonNull
    @Override
    public EmojiPackItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.emojipack_item, parent, false);
        return new EmojiPackItemViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull EmojiPackItemViewHolder holder, int position) {
        EmojiPack itemData = dataList.get(position);
        holder.showView(itemData, mUseSystemDefault,listener);
    }

    @Override
    public int getItemCount() {
        return dataList.size();
    }
}